#include <stdio.h>
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <netinet/in.h>
#define BUFSIZE 200


short PORT = 1234;
char *IP = "127.0.0.1";

int main()
{
	int sockfd = socket(PF_INET , SOCK_STREAM , 0);
	struct sockaddr_in addr;
	if((sockfd = socket(PF_INET , SOCK_STREAM , 0)) == -1)
		perror("socket创建失败") , exit(-1);
	memset(&addr , 0 , sizeof(addr));
	addr.sin_family = PF_INET;
	addr.sin_port = htons(PORT);
	addr.sin_addr.s_addr = inet_addr(IP);
	
	if(connect(sockfd , (struct sockaddr *)&addr , sizeof(addr)) == -1)
		perror("服务器连接失败") , exit(-1);
	printf("连接服务器成功...\n");

	char buf[BUFSIZE] = {};	
	while(1)
	{
		memset(buf , 0 , sizeof(buf));
		//printf("请输入:");
		scanf("%s",buf);
		send(sockfd , buf , strlen(buf) , 0);
	}

	close(sockfd);
	printf("关闭应用...\n");
	exit(0);
}
